package com.com.knowledgepaymentmanagementsystem.controller.marketing;
import com.com.knowledgepaymentmanagementsystem.pojo.marketing.Shipping;
import com.com.knowledgepaymentmanagementsystem.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.com.knowledgepaymentmanagementsystem.service.marketing.ShippingService;
import java.util.List;

/**
 * @author DELL
 * @version 1.0
 * @description: TODO
 * @date 2025/9/23 11:22
 */
@RestController
@Api(tags = "包邮管理")
@CrossOrigin
@RequestMapping("/shipping")
public class ShippingController {
    @Autowired
    private ShippingService shippingService;

    @ApiOperation(value = "查询包邮", httpMethod = "POST", notes = "查询包邮")
    @PostMapping("/find")
    public ResultUtil<List<Shipping>> getShippings(@RequestBody Shipping shipping) {
        List<Shipping> shippings = shippingService.getShipping(shipping);
        try {
            return new ResultUtil<>(200, "查询成功", shippings);
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "查询失败");

        }
    }

    @ApiOperation(value = "新增包邮", httpMethod = "POST", notes = "新增包邮")
    @PostMapping("insert")
    public ResultUtil insertShipping(@RequestBody Shipping shipping) {
        try {
            return new ResultUtil<>(200, "新增成功", shippingService.insertShipping(shipping));
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "新增失败");
        }
    }

    @ApiOperation(value = "删除包邮", httpMethod = "DELETE", notes = "删除包邮")
    @DeleteMapping("delete")
    public ResultUtil deleteShipping(@RequestParam Integer shippingId) {
        try {
            shippingService.deleteShipping(shippingId);
            return new ResultUtil<>(200, "删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "删除失败");
        }
    }
    // 修改
    @ApiOperation(value = "修改包邮", httpMethod = "PUT", notes = "修改包邮")
    @PutMapping("update")
    public ResultUtil updateShipping(@RequestBody Shipping shipping) {
        try {
            shippingService.updateShipping(shipping);
            return new ResultUtil<>(200, "修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "修改失败");
        }
    }
}